package feed

import (
	"gitee.com/mootok/mootok/src/models"
	"gitee.com/mootok/mootok/src/storage/database"
)

type Service struct{}


func (* Service) IsFans(userIds []int, actorId int, result *[]bool) error {
	// Create a map to store the query results
	var resultsMap []models.FollowRelation
	existsMap := make(map[int]bool)


	// Query the database to check for existing records
	err := database.Client.Model(&models.FollowRelation{}).
		Where(&models.FollowRelation{FansId: actorId}).
		Where("follow_id IN ?", userIds).
		Find(&resultsMap).Error

	if err != nil {
		return err
	}
	if err != nil {
		return err
	}
	for _, elem := range resultsMap {
		existsMap[elem.ID] = true
	}

	// Populate the result array in the exact same order
	for index, videoID := range userIds {
		if exists := existsMap[videoID]; exists {
			(*result)[index] = true
		} else {
			(*result)[index] = false
		}
	}

	return nil
}


func (* Service) IsFollower(userIds []int, actorId int, result *[]bool) error {
	// Create a map to store the query results
	var resultsMap []models.FollowRelation
	existsMap := make(map[int]bool)


	// Query the database to check for existing records
	err := database.Client.Model(&models.FollowRelation{}).
		Where(&models.FollowRelation{FollowId: actorId}).
		Where("fans_id IN ?", userIds).
		Find(&resultsMap).Error

	if err != nil {
		return err
	}
	if err != nil {
		return err
	}
	for _, elem := range resultsMap {
		existsMap[elem.ID] = true
	}

	// Populate the result array in the exact same order
	for index, videoID := range userIds {
		if exists := existsMap[videoID]; exists {
			(*result)[index] = true
		} else {
			(*result)[index] = false
		}
	}

	return nil
}